package com.activity.fragment;

import android.os.Bundle;
import android.view.View;

import com.activity.PersonInfoActivity;
import com.activity.adapter.ClockAdapter;
import com.activity.adapter.MonthAdapter;
import com.activity.shop.AttanceGroupActivity;
import com.activity.shop.ClockDetailActivity;
import com.api.param.UpdateUserParam;
import com.api.param.UserParam;
import com.api.viewModel.StoreVM;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.example.apple.ddhr_new.activity.widget.Dialog;
import com.example.apple.ddhr_new.utils.ActivityUtil;
import com.google.gson.Gson;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class MonthRecordFragment extends BaseListViewFragment<StoreVM> {

    MonthAdapter monthAdapter ;
    @Override
    public void createView() {
        super.createView();
        refreshLayout.setEnableLoadMore(false);
        monthAdapter = new MonthAdapter(mContext);
        recycleView.setAdapter(monthAdapter);

        monthAdapter.setOnChildClickListener(new GroupedRecyclerViewAdapter.OnChildClickListener() {
            @Override
            public void onChildClick(GroupedRecyclerViewAdapter adapter, BaseViewHolder holder, int groupPosition, int childPosition) {

                Bundle bundle = new Bundle();

                Gson gson = new Gson();
                bundle.putString("param",gson.toJson(monthAdapter.getData().get(childPosition)));
                ActivityUtil.startActivity(mContext,ClockDetailActivity.class,bundle);
            }
        });


        viewModel.record.observe(this,res->{

            headerFreshEnd();

            if(res!=null){

                monthAdapter.getData().clear();
                monthAdapter.getData().addAll(res);

                if(res.size()>0){
                    showEmpty(false);
                }else {
                    showEmpty(true);
                }
                monthAdapter.notifyDataChanged();
            }
        });



        headerFreshing();

    }

    @Override
    protected void headerFreshing() {

        addSubscription(viewModel.getMonthRecord(new UserParam()));
    }
}
